<html>
<head><meta charset="utf-8"><title>intrinsically bikesheddable · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html">intrinsically bikesheddable</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210809713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210809713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210809713">(Sep 21 2020 at 22:46)</a>:</h4>
<p>So we have a dilemma: portability includes implicitly "between the minds of Rustaceans", so we should think about how to say _everything_, and develop basically an internal glossary. And now, the question of "wait, what do we call intrinsics, exactly?" came up. Consensus seems to be against "intrinsic instructions" but aside from that so far it's still up in the air between:</p>
<ol>
<li>intrinsic functions</li>
<li>just "intrinsics"</li>
<li>"hardware intrinsics"</li>
<li>"intrinsic operations"</li>
<li>"SIMD operations"<br>
<a href="https://www.youtube.com/watch?v=O4irXQhgMqg">https://www.youtube.com/watch?v=O4irXQhgMqg</a><div class="youtube-video message_inline_image"><a data-id="O4irXQhgMqg" href="https://www.youtube.com/watch?v=O4irXQhgMqg"><img src="https://i.ytimg.com/vi/O4irXQhgMqg/default.jpg"></a></div></li>
</ol>



<a name="210810088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810088">(Sep 21 2020 at 22:51)</a>:</h4>
<p>My opinion/understanding is that an intrinsic (or intrinsic function, both are probably accurate) is something provided by the compiler that performs some special functionality that only the compiler can do correctly.  In the case of C/C++ these are specified by the vendors, mostly because they extend the language.  I'm not sure there's a strong distinction between an intrinsic like <code>_mm_add_ps</code> and <code>__builtin_cos</code>, even if one converts to a particular SIMD instruction and one converts to maybe a call to glibc or something</p>



<a name="210810170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810170">(Sep 21 2020 at 22:52)</a>:</h4>
<p>relevantly:<br>
<span class="user-mention silent" data-user-id="204346">Ashley Mannix</span> <a href="#narrow/stream/257879-project-portable-simd/topic/2020-09-21.20meeting/near/210808932">said</a>:</p>
<blockquote>
<p>We always have an opportunity in Rust to make topics really accessible so I'd love to do that here too <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>
</blockquote>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/257879-project-portable-simd/topic/2020-09-21.20meeting/near/210808901">said</a>:</p>
<blockquote>
<p>re: "intrinsics" vs. "instructions", "instructions" suggests it expands into a given asm, which is kinda Eh, I would prefer "functions" if "intrinsics" is considered Not OK, because vendors actually do refer to intrinsics as functions. intrinsic functions.</p>
</blockquote>
<p><span class="user-mention silent" data-user-id="322310">Jed</span> <a href="#narrow/stream/257879-project-portable-simd/topic/2020-09-21.20meeting/near/210808985">said</a>:</p>
<blockquote>
<p>I think "intrinsics" is fine -- many people interested in this will have had some contact with Intel or Power intrinsics for C.</p>
</blockquote>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/257879-project-portable-simd/topic/2020-09-21.20meeting/near/210809073">said</a>:</p>
<blockquote>
<p>yeah, "intrinsic functions" or even "simd operations" is best. I'd like to point out that <em>many</em> useful things we'll naturally offer will not be single instructions. Eg: simd sin / cos / tan is a whole big thing that's like 15 asm instructions long, but you absolutely want that in the API despite it not being "a single instruction"</p>
</blockquote>



<a name="210810340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810340">(Sep 21 2020 at 22:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="322310">Jed</span> <a href="#narrow/stream/257879-project-portable-simd/topic/2020-09-21.20meeting/near/210808985">said</a>:</p>
<blockquote>
<p>I think "intrinsics" is fine -- many people interested in this will have had some contact with Intel or Power intrinsics for C.</p>
</blockquote>
<p>My concern with this is I believe we shouldn't be making that assumption, since one of the goals (I think) is to make SIMD easier for everyone, including those who may have never used vendor intrinsics</p>



<a name="210810629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810629">(Sep 21 2020 at 22:58)</a>:</h4>
<p>I think a _little_ language overhead is to be expected, but also "intrinsics" are literally the things we are trying to abstract away, so internally we should be fine discussing intrinsics but  we should aim our external messaging @ "intrinsic functions" for clarity.</p>



<a name="210810664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810664">(Sep 21 2020 at 22:59)</a>:</h4>
<p>also is maximally googleable: <a href="https://en.wikipedia.org/wiki/Intrinsic_function">https://en.wikipedia.org/wiki/Intrinsic_function</a></p>



<a name="210810833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810833">(Sep 21 2020 at 23:00)</a>:</h4>
<p>I think I agree.  Even then I think we can specify just "function" or "SIMD operation" in many of those places where we might use "intrinsic" or "intrinsic function"</p>



<a name="210810860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jed <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810860">(Sep 21 2020 at 23:01)</a>:</h4>
<p>I don't have strong feelings on this terminology. Intel's <a href="https://software.intel.com/sites/landingpage/IntrinsicsGuide/">intrinsics guide</a> is quite useful and something I teach in my HPC class. Would it be feasible to maintain links in the docs from Rust portable intrinsics to vendor-specific intrinsics (with their hardware characteristics)?</p>



<a name="210810952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810952">(Sep 21 2020 at 23:02)</a>:</h4>
<p>I think that may belong in <code>core::arch</code>.  (and I agree that Intel's intrinsics guide is wonderful)</p>



<a name="210810973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210810973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210810973">(Sep 21 2020 at 23:02)</a>:</h4>
<p>We can link to the intrinsics in general but not for specific functions: we don't want the portable SIMD documentation to promise a specific intrinsic, as that's literally what we're abstracting away.</p>



<a name="210811013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jed <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811013">(Sep 21 2020 at 23:02)</a>:</h4>
<p>Existence of gather/scatter varies by architecture and can make a big difference in how one implements an algorithm. We love portability, but using 512b primitives with scatter/gather likely won't run well on hardware that does not have scatter/gather.</p>



<a name="210811058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811058">(Sep 21 2020 at 23:03)</a>:</h4>
<p>I think noting general performance characteristics is fine.</p>



<a name="210811158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jed <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811158">(Sep 21 2020 at 23:04)</a>:</h4>
<p>Sounds fair. One would hope than an fmadd portable intrinsic translates to an fmadd instruction when the target arch supports it.</p>



<a name="210811193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811193">(Sep 21 2020 at 23:05)</a>:</h4>
<p>Oh yeah, obviously, we're just not gonna specify _which one_, because yes, sometimes there are multiple!</p>



<a name="210811323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jed <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811323">(Sep 21 2020 at 23:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable/near/210811193">said</a>:</p>
<blockquote>
<p>Oh yeah, obviously, we're just not gonna specify _which one_, because yes, sometimes there are multiple!</p>
</blockquote>
<p>Yep, that's even true of an Intel intrinsic representing several instructions.</p>



<a name="210811327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811327">(Sep 21 2020 at 23:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="322310">Jed</span> <a href="#narrow/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable/near/210811013">said</a>:</p>
<blockquote>
<p>Existence of gather/scatter varies by architecture and can make a big difference in how one implements an algorithm. We love portability, but using 512b primitives with scatter/gather likely won't run well on hardware that does not have scatter/gather.</p>
</blockquote>
<p>I believe this is solvable by implementing a version of the algorithm with and without gather/scatter, and with some combination of <code>#[cfg]</code> and <code>#[target_feature]</code> selecting the appropriate one for your instruction set</p>



<a name="210811517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811517">(Sep 21 2020 at 23:09)</a>:</h4>
<p>"there is an fmadd intrinsic for that and it does not lower to an fmadd and we don't have a good reason why not" is basically a bug, but we may have a good reason. For instance, "so, about MMX: basically, that is Cursed Land."</p>



<a name="210811719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811719">(Sep 21 2020 at 23:12)</a>:</h4>
<p>"at the end of the day if you want a given asm so bad you're gonna have to write the assembly yourself."</p>



<a name="210811731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811731">(Sep 21 2020 at 23:12)</a>:</h4>
<p><em>[catching up]</em> Yeah, so I'd really like to say that the user is performing an "operation", as in "math operation", and a given operation might expand to different code depending on the target situation. And we don't <em>promise</em> that a given operation is a LLVM intrinsic and/or a CPU intrinsic. If people want to look at the current implementation and see that we're calling LLVM intrinsics that's fine for them, but importantly Rust won't always build with LLVM so we do <em>not</em> want to make LLVM related promises for the long term if we don't have to.</p>



<a name="210811971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210811971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210811971">(Sep 21 2020 at 23:15)</a>:</h4>
<p>And importantly, all of this portable SIMD stuff must be portable to systems with no SIMD support at all, so we can't even really promise that <code>f32x4 + f32x4</code> is a single instruction all the time.</p>



<a name="210812102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210812102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210812102">(Sep 21 2020 at 23:16)</a>:</h4>
<p>Even with SIMD, f32x8 will pretty much always polyfill to two instructions on SSE</p>



<a name="210812148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/intrinsically%20bikesheddable/near/210812148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/intrinsically.20bikesheddable.html#210812148">(Sep 21 2020 at 23:17)</a>:</h4>
<p>yeah we only have sse/sse2 on by default, so <em>one detail</em> we'll need to have in our tutorial is how to turn that default setting higher.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>